home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / dev / gui / gui4cli.lha / Gui4Cli / Ext / LVFormat / lv_func.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-16  |  2.6 KB  |  102 lines

  1.  
  2. // ==============================================================
  3. //    - Allocate & initialise a new List structure
  4. // ==============================================================
  5. // prototype needed
  6. void NewList (struct List *list);
  7.  
  8. struct List *getlist (struct ExecBase *SysBase, struct DosLibrary *DOSBase)
  9. {
  10.     struct List *ls;
  11.  
  12.     if (!(ls = (struct List *)AllocMem(sizeof(struct List), MEMF_CLEAR))) 
  13.         return (NULL);
  14.     NewList (ls);
  15.     return (ls);
  16. }
  17.  
  18. // ==============================================================
  19. //    - Free a lister List - return success
  20. // ==============================================================
  21. freelist (struct List *xls,
  22.       struct ExecBase *SysBase, struct DosLibrary *DOSBase)
  23. {
  24.     struct lister *ls, *nextls;
  25.  
  26.     // return if it's an empty list
  27.     if (IsListEmpty(xls)) return (0);
  28.  
  29.     // free the records
  30.     ls = (struct lister *)(xls->lh_Head);
  31.     while (nextls = (struct lister *)(ls->node.ln_Succ))
  32.     {
  33.        FreeMem (ls->start, (ls->length+1));
  34.        FreeMem (ls, sizeof(struct lister));
  35.        ls = nextls;
  36.     }
  37.  
  38.     FreeMem (xls, sizeof (struct List));
  39.     return (1);
  40. }
  41.  
  42. // ==============================================================
  43. //    - Add line to list - return success
  44. //    fls  = the fulist structure to add the line to
  45. //    buff = the line to add
  46. //    len  = it's strlen()
  47. // ==============================================================
  48. addline (struct fulist *fls, UBYTE *buff, LONG len,
  49.      struct ExecBase *SysBase, struct DosLibrary *DOSBase)
  50. {
  51.     struct lister *lstr;
  52.  
  53.     if ((!fls) || (!fls->ls)) return (0);
  54.  
  55.     if (lstr = getlister (buff, len, SysBase, DOSBase))
  56.     {   // adjust fulist & pointers & add
  57.         lstr->fls = fls;
  58.         AddTail ((struct List *)fls->ls, (struct Node *)lstr);
  59.         ++fls->totnum;
  60.         return (1);
  61.     }
  62.     return (0); 
  63. }
  64.  
  65. // ==============================================================
  66. //    Allocate & initialise a lister structure
  67. //    - buff - the line contents
  68. //    - len  - strlen(buff)
  69. //    NOTE : the lstr->fls field is not set!!
  70. // ==============================================================
  71. struct lister *getlister (UBYTE *buff, LONG len,
  72.           struct ExecBase *SysBase, struct DosLibrary *DOSBase)
  73. {
  74.     struct lister *lstr;
  75.  
  76.     if ((lstr = (struct lister *)AllocMem(sizeof (struct lister), MEMF_CLEAR)))
  77.     {  if ((lstr->start = (UBYTE *)AllocMem(len+1, MEMF_CLEAR)))
  78.        {
  79.           strcpy (lstr->start, buff);
  80.           lstr->length = len;
  81.           lstr->node.ln_Name = lstr->start;  // start of visible text
  82.           lstr->node.ln_Type = 100;
  83.           lstr->type         = 5;     // normal "file" type
  84.        }
  85.        else
  86.        {  FreeMem (lstr, sizeof (struct lister));
  87.           return (NULL);
  88.        }
  89.     }
  90.     else return (NULL);
  91.     return (lstr);
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.